using Autofac;
using Autofac.Extensions.DependencyInjection;
using Autofac.Extras.DynamicProxy;
using AutofacAopDemo.WebApi.Interceptors;
using AutofacAopDemo.WebApi.Services;

var builder = WebApplication.CreateBuilder(args);
builder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory());
builder.Host.ConfigureContainer<ContainerBuilder>(containerBuilder =>
{
    containerBuilder.RegisterType<CustomLoggingInterceptor>();

    containerBuilder.RegisterType<OrderService>()
        .As<IOrderService>()
        .InstancePerDependency()
        .EnableInterfaceInterceptors()
        .InterceptedBy(typeof(CustomLoggingInterceptor));
});
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();
app.UseSwagger();
app.UseSwaggerUI();
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();